package com.ruoyi.business.service.impl;

import com.ruoyi.business.domain.TIsvInfo;
import com.ruoyi.business.mapper.TIsvInfoMapper;
import com.ruoyi.business.service.ITIsvInfoService;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 支付宝服务商信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-18
 */
@Service("isvInfo")
public class TIsvInfoServiceImpl implements ITIsvInfoService 
{
    @Autowired
    private TIsvInfoMapper tIsvInfoMapper;

    /**
     * 查询支付宝服务商信息
     * 
     * @param id 支付宝服务商信息主键
     * @return 支付宝服务商信息
     */
    @Override
    public TIsvInfo selectTIsvInfoById(Long id)
    {
        return tIsvInfoMapper.selectTIsvInfoById(id);
    }

    /**
     * 查询支付宝服务商信息列表
     * 
     * @param tIsvInfo 支付宝服务商信息
     * @return 支付宝服务商信息
     */
    @Override
    @DataScope(userAlias = "t")
    public List<TIsvInfo> selectTIsvInfoList(TIsvInfo tIsvInfo)
    {
        return tIsvInfoMapper.selectTIsvInfoList(tIsvInfo);
    }

    /**
     * 新增支付宝服务商信息
     * 
     * @param tIsvInfo 支付宝服务商信息
     * @return 结果
     */
    @Override
    public int insertTIsvInfo(TIsvInfo tIsvInfo)
    {
        tIsvInfo.setIsvAliPublicPath(tIsvInfo.getIsvAliPublicPath().replace("/profile/upload", RuoYiConfig.getUploadPath()));
        tIsvInfo.setIsvAliRootPath(tIsvInfo.getIsvAliRootPath().replace("/profile/upload", RuoYiConfig.getUploadPath()));
        tIsvInfo.setIsvAppPublicPath(tIsvInfo.getIsvAppPublicPath().replace("/profile/upload", RuoYiConfig.getUploadPath()));
        tIsvInfo.setCreateTime(DateUtils.getNowDate());
        return tIsvInfoMapper.insertTIsvInfo(tIsvInfo);
    }

    /**
     * 修改支付宝服务商信息
     * 
     * @param tIsvInfo 支付宝服务商信息
     * @return 结果
     */
    @Override
    public int updateTIsvInfo(TIsvInfo tIsvInfo)
    {
        tIsvInfo.setUpdateTime(DateUtils.getNowDate());
        return tIsvInfoMapper.updateTIsvInfo(tIsvInfo);
    }

    /**
     * 批量删除支付宝服务商信息
     * 
     * @param ids 需要删除的支付宝服务商信息主键
     * @return 结果
     */
    @Override
    public int deleteTIsvInfoByIds(String ids)
    {
        return tIsvInfoMapper.deleteTIsvInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除支付宝服务商信息信息
     * 
     * @param id 支付宝服务商信息主键
     * @return 结果
     */
    @Override
    public int deleteTIsvInfoById(Long id)
    {
        return tIsvInfoMapper.deleteTIsvInfoById(id);
    }

    @Override
    public List<TIsvInfo> selectTIsvInfoListByType(int isvType)
    {
        TIsvInfo isvInfo = new TIsvInfo();
        isvInfo.setIsvType(isvType);
        if (!SysUser.isAdmin(ShiroUtils.getUserId()) && !SysUser.isDataAdmin(ShiroUtils.getSysUser().getRoles())){
            if(ShiroUtils.getSysUser().getMerchantType().equals("1")){
                isvInfo.setUserId(ShiroUtils.getUserId().toString());
            }else{
                isvInfo.setUserId(ShiroUtils.getSysUser().getAgentUid().toString());
            }
        }
        List<TIsvInfo> list = tIsvInfoMapper.selectTIsvInfoList(isvInfo);
        return list;
    }
}
